package com.luck.easyfoodbatch.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.adapter.FindAdapter;
import com.luck.easyfoodbatch.entity.News;
import com.luck.easyfoodbatch.ui.LatestInformationActivity;
import com.luck.easyfoodbatch.ui.ShopDataListActivity;
import com.luck.easyfoodbatch.util.Utils;
import com.luck.easyrecyclerview.EasyRecyclerView;
import com.luck.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.luck.easyrecyclerview.decoration.RecycleViewDivider;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/4/24.
 */

public class FindFragment01 extends BaseFragment {

    @BindView(R.id.recyclerView)
    EasyRecyclerView recyclerView;
    private View rootView;
    private List<News> list = new ArrayList<>();
    private FindAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.item_layout, container, false);
            ButterKnife.bind(this, rootView);
            initViews();
        }
        return rootView;
    }

    /**
     * 初始化
     */
    private void initViews() {
        News news;
        for (int i = 0; i < 4; i++) {
            news = new News();
            switch (i) {
                case 0:
                    news.setName("最新资讯");
                    news.setResources(R.mipmap.faxian_zuixin_1x);
                    break;
                case 1:
                    news.setName("好食推荐");
                    news.setResources(R.mipmap.faxian_haoshi_1x);
                    break;
                case 2:
                    news.setName("经营内参");
                    news.setResources(R.mipmap.faxian_neican_1x);
                    break;
                case 3:
                    news.setName("招商公告");
                    news.setResources(R.mipmap.faxian_zhaoshang_1x);
                    break;
            }
            list.add(news);
        }
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.addItemDecoration(new RecycleViewDivider(
                mContext, LinearLayoutManager.HORIZONTAL, Utils.dip2px(mContext, 0.5F), getResources().getColor(R.color.line_color)));
        recyclerView.setLayoutManager(manager);
        adapter = new FindAdapter(mContext);
        adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position, View v) {
                Bundle bundle = new Bundle();
                switch (position) {
                    case 0:
                        bundle.putInt("type", 1);
                        startAct(LatestInformationActivity.class, bundle);
                        break;
                    case 1:
                        startAct(ShopDataListActivity.class);
                        break;
                    case 2:
                        bundle.putInt("type", 2);
                        startAct(LatestInformationActivity.class, bundle);
                        break;
                    case 3:
                        bundle.putInt("type", 3);
                        startAct(LatestInformationActivity.class, bundle);
                        break;
                }
            }
        });
        adapter.addAll(list);
        recyclerView.setAdapter(adapter);
        recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);


            }
        });
    }

}
